package adapletplugin.dialogs;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public abstract class SingleComboDialog extends TitleAreaDialog
{

	private String fTitle;
	private String fDesc;
	private String fLabel;

	private Combo fTextBox;

	private String fResult;

	public SingleComboDialog(Shell parentShell, String title, String description, String label)
	{
		super(parentShell);

		fTitle = title;
		fDesc = description;
		fLabel = label;
	}

	@Override
	public void create()
	{
		super.create();

		setTitle(fTitle);
		setMessage(fDesc);
	}

	@Override
	protected Control createDialogArea(Composite parent)
	{
		GridLayout layout = new GridLayout();
		parent.setLayout(layout);

		Composite composite = new Composite(parent, SWT.NULL);
		layout = new GridLayout();
		layout.numColumns = 2;
		composite.setLayout(layout);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		Label label = new Label(composite, SWT.NULL);
		label.setText(fLabel);

		fTextBox = new Combo(composite, SWT.BORDER);
		
		populateData(fTextBox);
		
		fTextBox.setLayoutData(new GridData(SWT.FILL, SWT.NULL, true, false));

		return parent;
	}

	protected abstract void populateData(Combo combo);

	@Override
	protected void okPressed()
	{
		fResult = fTextBox.getText();
		super.okPressed();
	}

	public String getResultString()
	{
		return fResult;
	}

}
